package cn.tedu.basic;

import java.util.*;

//测试Map,无下标
public class Test4_Map {
    public static void main(String[] args) {
        //创建对象,必须添加键值对的数据，用来约束k和v的数据类型
        Map<Integer,String> map =new HashMap();
        //调用方法
        map.put(8888,"liuyun");
        map.put(9999,"yumin");
        map.put(7777,"chudexin");
        System.out.println(map);
        map.put(7777,"cangjingkong");
        System.out.println(map);
        System.out.println(map.get(8888));
        System.out.println(map.containsKey(7777));
        System.out.println(map.keySet());
        System.out.println(map.containsValue("uvvbil"));
        System.out.println(map.equals(9999));
        System.out.println(map.hashCode());
        System.out.println(map.isEmpty());
        System.out.println(map.remove(9999));
        System.out.println(map.size());
//        map.clear();
        //迭代1
            Set<Integer> s= map.keySet();
            for(Integer s1 : s){
                String st =map.get(s1);
                if (st=="yumin"){
                    System.out.println("right");
                }
                System.out.println(s1 + st);
            }
            //迭代2
        Collection<String> col =map.values();
        Iterator<String> It =col.iterator();
        while (It.hasNext()){
            String str=It.next();
            System.out.println(str);
        }
        Collection<String> coll =map.values();
        Iterator<String> It1 =coll.iterator();
        while (It1.hasNext()){
            String st =It1.next();
            System.out.println(st);
        }
        for (String st1 : coll){
            System.out.println(st1);
        }
        //或
        for(String str1 : col){
            System.out.println(str1);
        }
        //迭代3
        Set<Map.Entry<Integer,String>> se=map.entrySet();
       for (Object ob : se){
           System.out.println(ob);
       }
        Set<Map.Entry<Integer, String>> entries = map.entrySet();
       for (Object  obj : entries){
           System.out.println(obj);
       }
        Set<Map.Entry<Integer, String>> entries1 = map.entrySet();
       for (Map.Entry<Integer,String> ma : entries1){
           Integer a =ma.getKey();
           String b =ma.getValue();
           System.out.println(a + b );
       }
    }
}
